<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Alpha-欢迎您</title>
    <link rel="shortcut icon" href="../icon/title.ico"/>
    <link rel="stylesheet" href="../css/index.css">
    <link rel="stylesheet" href="../css/bootstrap3.3.7.min.css">

    <script src="../js/jquery-1.10.2.min.js"></script>
    <script src="../js/bootstrap3.3.7.min.js"></script>
    <script src="../js/index.js"></script>
    <style>
        .content{
            width: 80%;margin: auto}
        h3{
            width: 100%;text-align: center;padding: 20px 0;}

    </style>
    <script>

    </script>
</head>
<body>

<div class="warp">
    <div>
        <h1><a href="../index.html">Alpha</a></h1>
    </div>
    <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse"
                        data-target="#example-navbar-collapse">
                    <span class="sr-only">切换导航</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#"></a>
            </div>
            <div class="collapse navbar-collapse" id="example-navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">javascript</a></li>
                    <li><a href="#">css</a></li>
                    <li><a href="#">jquery</a></li>
                    <li><a href="#">angular</a></li>
                    <li><a href="#">其他</a></li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="img">
        <img src="../images/javaScript.png" style=";height: 300px;background:#ccc;" alt="">
    </div>
    <hr>
    <!--返回顶部箭头-->
    <div id="top" style="width: 50px;height: 50px;background-color: #999;position: fixed;right: 50px;bottom:50px;text-align: center;line-height: 50px;display: none;">
        <b>
            <a style="text-decoration:none;color:#fff;;" href="javascript:;">顶部</a>
        </b>
    </div>

    <div class="content">
        <h3>get和post数据交互</h3>
        <div>
            <p>1.AJAX的get和post 是与服务器交换数据的技术，它在不重载全部页面的情况下，实现了对部分网页的更新。</p>
            <p style="padding-left: 10px;">get:容量小（4k-10k）不适合密码提交,不适合大文件传输,适合用于网页分享,get是有本地缓存的</p>
            <p style="padding-left: 10px;">post:容量大(2G)，相对get,比较安全,post是没有缓存的</p>
            <p>2.jquery的<b>get</b>(url,fn)方法：url:请求的API,fn：请求成功时回调的函数</p>
        <pre>
        $(document).ready(function () {
            $("#btn").click(function () {
                //清除本地缓存："../text/1.text/？t="+new Date().getTime()
                //$.get('../text/1.text', function (data,status) {
                //data:请求的数据;status:成功状态
                $.get('../text/1.text', function (data,status) {
                alert("请求到的数据："+data+":成功状态"+status)
                });
            })
        });
        </pre>
            <p><input class="btn btn-info" disabled  type="button" value="没有服务器无法使用" id="btn"></p>
        </div>

        <div>
            <p>3.jquery的<b>post</b>(url,data,fn):url:请求地址;data:要传送的数据;fn：成功回调函数</p>
            <pre>
            $(document).ready(function () {
                $("#btn2").click(function () {
                    $.post("../text/1.php",{name:"liu",value:'18'}, function (data,status) {
                        alert(data+":"+status)
                    });
                });
            });
            </pre>
            <p>
                <input class="btn btn-info" disabled type="button" value="没有服务器无法使用" id="btn2" >
            </p>
        </div>
        <div>
            <p>4.angular.js的get/post通用方法：</p>
            <pre>
            var app = angular.module('myApp', []);
                //controller控制器 siteCtrl是控制器名字;
            app.controller('siteCtrl', function($scope, $http) {
                $http({
                //根据需要修改不同的GET或POST请求方式
                method: 'GET',
                url: '../text/1.text'
                }).then(function successCallback(response) {
                    //数据请求成功执行的代码
                $scope.names = response.data.sites;

                }, function errorCallback(response) {
                    // 请求失败执行代码
                });

            });
            </pre>
            <p>angular中的get方法：</p>
            <pre>
            var app = angular.module('myApp', []);
                app.controller('siteCtrl', function($scope, $http) {
                  $http.get("url地址")
                    //data后面跟着是个json数组，  i sites是数组的name
                //***json数组一定要用“双引号”
                  .then(function (response) {$scope.names = response.data.sites;});
            });
            </pre>
            <p>angular中的post方法：</p>
            <pre>
            var app = angular.module('myApp', []);
                app.controller('siteCtrl', function($scope, $http) {
                  $http.post("url地址")
                    //data后面跟着是个json数组，  i sites是数组的name
                //***json数组一定要用“双引号”
                  .then(function (response) {$scope.names = response.data.sites;});
            });
            </pre>
        </div>
        <div id="get"></div>

    </div>
    <hr>
    <div class="footer">
        <div>
            <img src="" alt="">
            <img src="" alt="">
            <img src="" alt="">
            <img src="" alt="">
            <img src="" alt="">
            <img src="" alt="">
        </div>
        <div class="footer-bottom">
            <p>这是一段内容</p>
        </div>
    </div>
</div>

</body>
</html>
<script>
    $(document).ready(function () {
        /*get方法*/
        $("#btn").click(function () {
            $.get('../text/1.text/?t='+new Date().getTime(), function (data,status) {
                alert("请求到的数据："+data+":成功状态"+status)
            });
        });
        /*post方法*/
        $("#btn2").click(function () {
            $.post("../text/1.php",{name:"liu",value:'18'}, function (data,status) {
                alert(data+":"+status)
            });
        });
    });
</script>
<script>
    window.addEventListener('scroll', function () {
        var oTop=document.getElementById('top');
        var oH=document.documentElement.clientHeight;
        var oS=document.body.scrollTop;
        if(oH+oS>oH){
            oTop.style.display="block";

        }else {
            oTop.style.display="none";
        }
        oTop.onclick= function () {
            var timer=null;
            clearInterval(timer);
            timer=setInterval(function () {
                console.log(oS)
                document.body.scrollTop=(oS*=0.8);
                if (oS<=1){
                    oS=0;
                    clearInterval(timer);
                    oTop.style.display="none";
                    //alert(oS)
                }
                console.log(oS)
            },30)
        }
    },false);
</script>